

import java.io.*;
import java.net.*;

public class TCPServerPersoana extends Thread {
    private ServerSocket serverSocket;
    private int port;
    private Persoana administratorServer;

    public TCPServerPersoana(int port) {
        this.port = port;
        this.administratorServer = new Persoana("Popescu", "Ion", "popescu.ion@yahoo.com");
    }

    public void run() {
        try {
            this.serverSocket = new ServerSocket(port);
        } catch (Exception e) {
            System.err.println("Exceptie la crearea ServerSocket-ului: " + e);
            e.printStackTrace();
            return;
        }


        Socket clientSocket = null;

        try {
            while (true) {
                System.out.println("[TCPServer] Accepting a new connection");
                clientSocket = this.serverSocket.accept();
                System.out.println("Trimitere raspuns client");
                ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
                out.writeObject(this.administratorServer);
                out.close();
            }
        } catch (Exception e) {
            System.out.println("Eroare transmitere obiect/acceptare conexiune");
            e.printStackTrace();
        }
        try {
            this.serverSocket.close();
        } catch (Exception e) {
            System.err.println("ServerSocket close exception: " + e);
            e.printStackTrace();
        }

    }

    public static void main(String... arg) {
        TCPServerPersoana server = new TCPServerPersoana(20001);
        server.start();


    }
}
